package com.lemurian.bankdata.servicebean;

import java.util.List;

import javax.persistence.Transient;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.lemurian.bankdata.bean.UserDAO;
import com.lemurian.bankdata.dto.UserDTO;
import com.lemurian.bankdata.lite.struts.PartialList;
import com.lemurian.bankdata.services.UserService;
import com.lemurian.entity.Menu;
import com.lemurian.entity.User;

@Service("userService")
@Transactional(readOnly=true)
public class UserBean implements UserService {

	@Autowired private UserDAO dao;
	
	@Override
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public void delete(User entity) {
		dao.delete(entity);
	}

	@Override
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public void delete(int id) {
		dao.delete(id);
	}

	@Override
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public int delete(String sql) {
		return dao.delete(sql);
	}

	@Override
	@Transactional(readOnly=true,propagation=Propagation.REQUIRED)
	public List<User> findAll() {
		return dao.findAll();
	}

	@Override
	@Transactional(readOnly=true,propagation=Propagation.REQUIRED)
	public List<User> findAll(Order order) {
		return dao.findAll(order);
	}

	@Override
	@Transactional(readOnly=true,propagation=Propagation.REQUIRED)
	public List<User> findByCriteria(Order order, Criterion... criterion) {
		return dao.findByCriteria(order, criterion);
	}

	@Override
	@Transactional(readOnly=true,propagation=Propagation.REQUIRED)
	public PartialList<User> findByCriteria(int start, int count, Order order, Criterion... criterion) {
		return dao.findByCriteria(start, count, order, criterion);
	}

	@Override
	@Transactional(readOnly=true,propagation=Propagation.REQUIRED)
	public User findByCriteria(Criterion... criterion) {
		return dao.findByCriteria(criterion);
	}

	@Override
	@Transactional(readOnly=true,propagation=Propagation.REQUIRED)
	public User findById(int id) {
		return dao.findById(id);
	}

	@Override
	@Transactional(readOnly=true,propagation=Propagation.REQUIRED)
	public User load(int id) {
		return dao.load(id);
	}

	@Override
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public User save(User entity) {
		return dao.save(entity);
	}

	@Override
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public User update(User entity) {
		return dao.update(entity);
	}

	@Override
	@Transactional(readOnly=true,propagation=Propagation.REQUIRED)
	public User authenticate(String loginId, String password) {
		return dao.authenticate(loginId, password);
	}

	@Override
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public boolean saveSessionId(User user, String sessionId) {
		return dao.saveSessionId(user, sessionId);
	}

	@Override
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public boolean validateUserSession(User user, String sessionId) {
		return dao.validateUserSession(user, sessionId);
	}

	@Override
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public void failCount(String loginId) {
		dao.failCount(loginId);
	}

	@Override
	@Transactional(readOnly=true,propagation=Propagation.REQUIRED)
	public <T extends User> List<Menu> getListMenu(T user) {
		return dao.getListMenu(user);
	}

	@Override
	@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
	public User resetFailCount(User user) {
		return dao.resetFailCount(user);
	}

	@Override
	@Transactional(readOnly=true,propagation=Propagation.REQUIRED)
	public List<User> getUserByUserType(int userType) {
		return dao.getUserByUserType(userType);
	}

	@Override
	@Transient
	public PartialList<UserDTO> listUser(int start, int count, String ascDesc, String orderBy, String name, String email) {
		return dao.listUser(start, count, ascDesc, orderBy, name, email);
	}

}
